package com.bangdao.app.jetpacktest.jetpack.databinding;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.bangdao.app.jetpacktest.R;
import com.bangdao.app.jetpacktest.databinding.ActivityTwoWayDataBinding2Binding;
import com.bangdao.app.jetpacktest.databinding.ActivityTwoWayDataBinding3Binding;
import com.bangdao.app.jetpacktest.jetpack.databinding.viewmodel.TwoWayBindingViewModel2;
import com.bangdao.app.jetpacktest.jetpack.databinding.viewmodel.TwoWayBindingViewModel3;

/**
 * 双向绑定
 */
public class TwoWayDataBindingActivity3 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //创建DataBinding
        ActivityTwoWayDataBinding3Binding binding =
                DataBindingUtil.setContentView(this, R.layout.activity_two_way_data_binding3);
        //创建ViewModel
        TwoWayBindingViewModel3 viewModel3 = new ViewModelProvider(this).get(TwoWayBindingViewModel3.class);
        //建立绑定关系
        binding.setViewModel(viewModel3);
        //用LiveData配合DataBinding的话，要手动将生成的Binding布局类和LifecycleOwner关联起来
        binding.setLifecycleOwner(this);
    }
}